package com.sunjob.mrogeteway.filter;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.cloud.gateway.filter.factory.GatewayFilterFactory;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Wangzurong
 * @create 2022-08-05 8:32
 */
@Component
public class MROIpPartLimiterGatewayFilterFactory extends AbstractGatewayFilterFactory<MROIpPartLimiterGatewayFilterFactory.Config> {
    @Autowired
    RedisTemplate<String, Object> redisTemplate;

    public MROIpPartLimiterGatewayFilterFactory() {
        super(Config.class);
    }


    @Override
    public GatewayFilter apply(Config config) {

        return new MROIpPartLimiterFilter(redisTemplate.opsForValue(),config.getLimit(),config.getLimitTime());
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Config {
        private int limit;
        private long limitTime;
    }
}
